package cn.wolfcode.student.service.impl;

import cn.wolfcode.domain.PageResult;
import cn.wolfcode.domain.QueryObject;
import cn.wolfcode.student.dao.StudentDAO;
import cn.wolfcode.student.dao.impl.StudentDAOImpl;
import cn.wolfcode.student.domain.Student;
import cn.wolfcode.student.service.StudentService;

import java.util.List;

public class StudentServiceImpl implements StudentService {
    private StudentDAO studentDAO = new StudentDAOImpl();

    @Override
    public void save(Student student) {
        Long id = student.getId();
        if (id != null) {
            studentDAO.edit(student);
        } else {
            studentDAO.add(student);
        }
    }

    @Override
    public void delById(Long id) {
        studentDAO.delById(id);
    }

    @Override
    public Student selOne(Long id) {
        return studentDAO.selOne(id);
    }

    @Override
    public List<Student> selAll() {
        return studentDAO.selAll();
    }

    @Override
    public PageResult<Student> query(QueryObject qo) {
        List<Student> data = studentDAO.selForList(qo);
        int totalCount = studentDAO.selForCount(qo);
        return new PageResult<>(qo.getCurrentPage(), qo.getPageSize(), totalCount, data);
    }
}








